/**
 * 3. 无重复字符的最长子串
 * https://leetcode.cn/problems/longest-substring-without-repeating-characters/description/?envType=study-plan-v2&envId=top-100-liked
 */
class Solution2 {
    public int lengthOfLongestSubstring(String s) {
        int ret = 0, n = s.length();
        char[] ch = s.toCharArray();
        int[] hash = new int[128];

        for(int left = 0, right = 0; right < n; right++) {
            //进窗口
            hash[ch[right]]++;
            //判断
            while(hash[ch[right]] > 1) {
                //出窗口
                hash[ch[left++]]--;
            }
            //更细结果
            ret = Math.max(ret, right - left + 1);
        }
        
        return ret;
    }
}